<template>
	<div>
		<!-- 顶部滑动条 -->
		<div id="slider" class="mui-slider">
			<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
				<div class="mui-scroll">
					<a :class="['mui-control-item',item.id == 0 ? 'mui-active' : '']" v-for="item in cates" :key="item.id" @click="getPhotoListByCateId(item.id)">
						{{item.title}}
					</a>
				</div>
			</div>
		</div>
		<!-- 图片列表区域 -->
		<ul class="photo-list">
			<li v-for="item in list" :key="item.title">
				<img v-lazy="item.img_url">
				<div class="info">
					<h1 class="info-title">{{item.title}}</h1>
					<div class="info-body">
						{{item.zhaiyao}}
					</div>
				</div>
			</li>
		</ul>
	</div>
</template>

<script>
	//1.导入mui的js文件
	import mui from '../../lib/mui/dist/js/mui.js'
	import { Lazyload } from 'mint-ui';
	
	export default{
		data(){
			return{
				cates:[],//所有分类的列表数组
				list:[],//图片列表的数组
				id:this.$route.params.id
			}
		},
		mounted(){//当组件中的DOM结构被渲染好并放到页面中后,会执行这个钩子函数
		//如果要操作元素了,最好在mouted里面操作,因为这时候dom元素里面是最新的
			//2. 初始化滑动控件
			mui('.mui-scroll-wrapper').scroll({
				deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
			});
		},
		created(){
			this.getAllCategory()
			this.getPhotoListByCateId(0)
		},
		methods:{
			getAllCategory(){
				this.axios.get('/getphotolist').then(result =>{
					if(result.data.err_code === 0){
						var all={"title":"全部","id":0};
						this.cates = result.data.getphotolist
						this.cates.unshift(all)
					}
				})
			},
			getPhotoListByCateId(cateId){
				//根据分类id获取图片
				this.axios.get('/getimages'+'?id='+cateId)
				 .then( result =>{
					 if(result.data.err_code == 0){
						 console.log(result.data)
						 this.list = result.data.images
					 }
				 })
			}
		}
	}
</script>

<style lang="scss" scoped>
 	* {
 		touch-action: pan-y;
 	} 
	.photo-list{
		list-style: none;
		margin: 0;
		padding: 10px;
		padding-bottom:0px;
		li{
			position: relative;
			background-color: #ccc;
			text-align: center;
			margin-bottom: 10px;
			box-shadow: 0 0 9px #999;
			img{
				width: 100%;
				height: auto;
				vertical-align: middle;
			}
			img[lazy="loading"]{
				width: 40px;
				height: 300px;
				margin:auto;
			}
		}
		.info{
			width: 100%;
			position: absolute;
			bottom: 0px;
			color: #fff;
			text-align: left;
			background: rgba(0,0,0,0.4);
			.info-title{
				font-size: 14px;
			}
			.info-body{
				font-size: 13px;
			}
		}
	}
	
</style>
